using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace UnitTesting.Fixturing
{
	[Serializable]
	public class NotMatchedArgumentException : Exception
	{
		//
		// For guidelines regarding the creation of new exception types, see
		//    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
		// and
		//    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
		//

		public NotMatchedArgumentException()
		{
		}

		public NotMatchedArgumentException(string message) : base(message)
		{
		}

		public NotMatchedArgumentException(string message, Exception inner)
			: base(message, inner)
		{
		}

		internal NotMatchedArgumentException(IEnumerable<IArgument> arguments)
			: base(string.Format(CultureInfo.InvariantCulture, "Some arguments are not matched and remained: " + Environment.NewLine + "{0}", ConvertArgumentsToString(arguments)))
		{
		}

		static string ConvertArgumentsToString(IEnumerable<IArgument> arguments)
		{
			return arguments.Aggregate(
				new StringBuilder(),
				(builder, argument) => builder.AppendLine(argument.ToString()),
				builder => builder.Remove(builder.Length - Environment.NewLine.Length, Environment.NewLine.Length).ToString());
		}

		protected NotMatchedArgumentException(
			SerializationInfo info,
			StreamingContext context) : base(info, context)
		{
		}
	}
}